<template>
  <div style="width: 100%; height: 100%">
    <el-header class="el-header">
      <div class="header-back-container">
        <div class="el-page-header">
          <div class="el-page-header__left" @click="onBack">
            <i class="el-icon-back"></i>
            <div class="el-page-header__title">返回</div>
          </div>
          <div class="el-page-header__content">
            <div class="title-box">
              <div class="title">
                {{ editData && editData.id ? "编辑巡查点" : "新增巡查点" }}
              </div>
            </div>
          </div>
        </div>
      </div>
    </el-header>
    <el-main style="height: calc(100% - 60px - 60px); overflow-y: auto">
      <div class="info-title">基础信息</div>
      <el-form
        :model="formBasic"
        :rules="rulesBasic"
        inline
        ref="refFormBasic"
        label-width="110px"
        label-position="top"
        style="margin: 0px 8px; padding: 0px 20px"
      >
        <el-form-item label="巡查点名称" prop="pointName">
          <el-input
            v-model.trim="formBasic.pointName"
            placeholder="请输入"
            maxlength="30"
            style="width: 340px"
            size="small"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item
          size="small"
          label="组织机构"
          prop="orgId"
          v-if="user.roleName == 'TENANT_ADMIN' || user.roleName == 'ORG_ADMIN'"
        >
          <!-- v-if="!editData.id" -->
          <TreeSearchAdd
            style="width: 340px"
            @changeOrgId="changeOrgId"
            :clearable="false"
            ref="refTreeSearchAdd"
            v-if="!editData.id"
          >
            <!-- :disabled="editData && editData.id ? true : false" -->
          </TreeSearchAdd>
          <el-input
            v-else
            disabled
            style="width: 340px"
            v-model="orgName"
            placeholder="组织机构"
          ></el-input>
        </el-form-item>
        <el-form-item size="small" label="联网单位" prop="unitId">
          <el-select
            size="small"
            style="width: 340px"
            v-model="formBasic.unitId"
            placeholder="请选择联网单位"
            filterable
            @change="changeunitId"
            :disabled="editData && editData.id ? true : false"
          >
            <el-option
              v-for="item in orgList"
              :label="item.orgName"
              :value="item.id"
              :key="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item size="small" label="建筑物" prop="buildingId">
          <el-select
            size="small"
            style="width: 340px"
            @change="changeBuildings"
            v-model="formBasic.buildingId"
            v-loadMore="loadBulidings"
            placeholder="请选择建筑物"
            filterable
            remote
            :remote-method="remoteBuildings"
            :disabled="editData && editData.id ? true : false"
          >
            <el-option
              v-for="item in buildings"
              :label="item.name"
              :value="item.id"
              :key="item.id"
            >
            </el-option>
            <div
              class="div_box"
              v-loading="loading2"
              :style="loading2 ? '' : 'display: none;'"
            ></div>
          </el-select>
        </el-form-item>
        <el-form-item size="small" label="楼层" prop="floorId">
          <el-select
            size="small"
            style="width: 340px"
            clearable
            @change="changeFloors"
            v-loadMore="loadFloors"
            v-model="formBasic.floorId"
            placeholder="请选择楼层"
            filterable
            remote
            :remote-method="remoteFloors"
            :disabled="editData && editData.id ? true : false"
          >
            <el-option
              v-for="item in floors"
              :label="item.name"
              :value="item.id"
              :key="item.id"
            >
            </el-option>
            <div
              class="div_box"
              v-loading="loading3"
              :style="loading3 ? '' : 'display: none;'"
            ></div>
          </el-select>
        </el-form-item>
        <el-form-item size="small" label="安装点" prop="spaceId">
          <el-select
            size="small"
            style="width: 340px"
            clearable
            @change="changeSpaces"
            v-loadMore="loadSpaces"
            v-model="formBasic.spaceId"
            placeholder="请选择安装点"
            filterable
            remote
            :remote-method="remoteSpaces"
            @clear="clearSpaces"
            :disabled="editData && editData.id ? true : false"
          >
            <el-option
              v-for="item in spaces"
              :label="item.name"
              :value="item.id"
              :key="item.id"
            >
            </el-option>
            <div
              class="div_box"
              v-loading="loading4"
              :style="loading4 ? '' : 'display: none;'"
            ></div>
          </el-select>
        </el-form-item> -->
        <el-form-item label="详细地址" prop="address">
          <el-input
            v-model="formBasic.address"
            placeholder="请输入"
            maxlength="30"
            style="width: 340px"
            size="small"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="标签编号" prop="tagNumber">
          <el-input
            v-model="formBasic.tagNumber"
            placeholder="请输入"
            maxlength="20"
            style="width: 340px"
            size="small"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="打卡类型" prop="clockInType">
          <el-select
            size="small"
            style="width: 340px"
            v-model="formBasic.clockInType"
            placeholder="请选择打卡类型"
            filterable
            :disabled="editData && editData.id ? true : false"
          >
            <el-option
              v-for="item in clockInTypeList"
              :label="item.label"
              :value="item.value"
              :key="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div class="info-title">巡查项配置</div>
      <div class="associated-devices">
        <div class="header" style="margin-bottom: 10px">
          <div class="header_left">
            <el-button
              class="el_button"
              size="small"
              icon="el-icon-plus"
              @click="addClick"
            >
              新增
            </el-button>
            <!-- <el-button
              class="el_button"
              size="small"
              icon="el-icon-delete"
              type="info"
              style="margin-left: 15px"
              @click="onDelClickBatch"
            >
              删除
            </el-button> -->
          </div>
          <div class="header_right"></div>
        </div>
        <div class="content">
          <el-table
            :data="dataList"
            class="table"
            max-height="400"
            :header-cell-style="headerStyle"
            ref="refTable"
            row-key="deviceCode"
            :span-method="objectSpanMethod"
          >
            <!-- @selection-change="batchSelect" -->
            <!-- <el-table-column
              align="center"
              type="selection"
              :reserve-selection="true"
              width="60"
            ></el-table-column> -->
            <el-table-column
              align="center"
              prop="name"
              label="巡查项分类"
              min-width="100"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              prop="content"
              label="巡查项"
              min-width="100"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column align="center" label="操作" width="150">
              <template slot-scope="scope">
                <el-tooltip
                  class="item"
                  effect="dark"
                  content="删除"
                  placement="bottom"
                >
                  <i
                    @click="onDel(scope.row)"
                    class="iconfont shanchu tableBtnIcon"
                  ></i>
                </el-tooltip>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <div style="height: 14px"></div>
    </el-main>
    <el-footer class="dialog-footer">
      <el-button size="small" @click="closeDialog">取 消</el-button>
      <el-button
        size="small"
        type="primary"
        @click="onSubmit"
        v-preventReClick="1000"
        >确 定</el-button
      >
    </el-footer>
    <choseDevice
      ref="refChoseDevice"
      :orgId="formBasic.orgId"
      :unitId="formBasic.unitId"
      :buildingId="formBasic.buildingId"
      :floorId="formBasic.floorId"
      :spaceId="formBasic.spaceId"
      :treeData="treeData"
      @getDevices="getDevices"
    />
    <!-- <choseUser
      ref="refChoseUser"
      :orgId="formBasic.orgId"
      :unitId="formBasic.unitId"
      :userData="userData"
      @getUsers="getUsers"
    /> -->
  </div>
</template>

<script>
import tableStyleMixin from "../mixins/table-style";
import { mapState } from "vuex";
import {
  reqOrgList,
  reqSpaceManager,
  reqFireOsList,
  reqFireFacilityAdd,
  reqFireFacilityEdit,
  reqCategoryFireFacilityList,
  reqFireFacilityById,
} from "@/api/api";
import { reqPatrolPointAdd } from "@api/patrol.js";
import { reqRuleEdit } from "@api/rule";
import { reqByProductKey } from "@/api/rule";
import choseDevice from "./choseDevice.vue";
import choseUser from "./choseUser.vue";
import TreeSearchAdd from "@components/TreeSearchAdd.vue";
import loadMore from "@mixin/loadMore";

export default {
  name: "",
  props: ["showIndex", "editData"],
  components: { TreeSearchAdd, choseDevice, choseUser },
  watch: {
    showIndex(val) {
      if (JSON.stringify(this.editData) == "{}") {
        this.isEditInfo = false;
        if (
          this.user.roleName == "TENANT_ADMIN" ||
          this.user.roleName == "ORG_ADMIN"
        ) {
          if (this.$refs.refTreeSearchAdd) {
            this.$refs.refTreeSearchAdd.getDataList();
          }
        } else if (this.user.roleName == "UNIT_ADMIN") {
          this.getOrgList();
        }
      } else {
        // 编辑
        this.isEditInfo = true;
        let data = JSON.parse(JSON.stringify(this.editData));
        this.formBasic.address = data.address;
        this.formBasic.pointName = data.pointName;
        this.formBasic.tagNumber = data.tagNumber;
        this.formBasic.clockInType = data.clockInType;
        this.formBasic.unitId = data.unitId;
        this.formBasic.orgId = data.orgId;
        this.getOrgList();

        // 巡查项配置
        this.treeData = data.pointItemList;
        this.prepareData();
      }
    },
  },
  mixins: [tableStyleMixin, loadMore],
  data() {
    return {
      isEditInfo: false,
      orgName: "",
      formBasic: {
        address: "",
        pointName: "",
        tagNumber: "",
        clockInType: "",
        unitId: "",
        // spaceId: "",
        // buildingId: "",
        // floorId: "",
        orgId: "",
      },
      rulesBasic: {
        pointName: [
          { required: true, message: "请输入消防设施名称", trigger: "blur" },
        ],
        clockInType: [
          { required: true, message: "请选择打卡类型", trigger: "change" },
        ],
        orgId: [{ required: true, message: "请选择机构", trigger: "change" }],
        unitId: [{ required: true, message: "请选择单位", trigger: "change" }],
        buildingId: [
          { required: true, message: "请选择建筑物", trigger: "change" },
        ],
        floorId: [{ required: true, message: "请选择楼层", trigger: "change" }],
        spaceId: [
          { required: true, message: "请选择安装点", trigger: "change" },
        ],
        tagNumber: [
          { required: true, message: "请输入设施编号", trigger: "blur" },
        ],
      },
      clockInTypeList: [
        { label: "全部", value: "0" },
        { label: "扫码", value: "1" },
        { label: "NFC", value: "2" }, 
      ],
      treeData: [],
      userData: [],
      dataList: [],
      batchDataList: [],
      orgList: [],
      buildings: [],
      buildingsName: "",
      sysInstanceIndex2: 0,
      sysInstanceTotalPages2: 10,
      loading2: false,
      floors: [],
      floorId: "",
      floorsName: "",
      floorsName2: "",
      sysInstanceIndex3: 1,
      sysInstanceTotalPages3: 10,
      loading3: false,

      spaces: [],
      loading4: false,
      spacesName: "",
      spacesName2: "",
      sysInstanceIndex4: 1,
      sysInstanceTotalPages4: 10,
      choseData1: [],
    };
  },
  computed: {
    ...mapState(["user", "spacesManage"]),
  },
  methods: {
    // ——————————————————————————————————————单位
    async getOrgList() {
      let { tenantId, userId, roleName } = this.user;
      const res = await reqOrgList({
        tenantId,
        userId,
        roleName,
        orgName: "",
        parentId: this.formBasic.orgId || "",
        type: "4",
      });
      if (res.code !== 20000) return this.$modal.notifyWarning(res.message);
      this.orgList = res.data.rows;
    },
    // 根据id查询消防设施信息
    async getFireFacilityById(id) {
      let res = await reqFireFacilityById(id);
      if (res.code !== 20000) return this.$modal.notifyError(res.message);
      let { info } = res.data;
      this.orgName = info.orgName;
      this.formBasic.address = info.address;
      this.formBasic.pointName = info.pointName;
      this.formBasic.tagNumber = info.tagNumber;
      this.formBasic.clockInType =
        info.status == "0" ? "全部" : info.status == "1" ? "扫码" : "NFC";
      this.formBasic.unitId = info.unitId;
      this.formBasic.spaceId = info.spaceId;
      this.formBasic.buildingId = info.buildingId;
      this.formBasic.floorId = info.floorId;
      this.formBasic.orgId = info.orgId;
      if (info.deviceList.length) {
        info.deviceList.forEach((item) => {
          if (item.type == 1) {
            item.imei = item.deviceCode;
            this.choseData1.push(item);
          }
        });
        this.dataList = info.deviceList;
      } else {
        this.choseData1 = [];
        this.dataList = [];
      }

      this.getOrgList();
      this.getBuildList();
      this.getFloors();
      this.getSpaces();
      this.getCategoryFireFacilityList();
      // this.$nextTick(() => {
      //   this.$refs.refTreeSearchAdd.getDataList(this.formBasic.orgId); //机构列表
      //   this.$refs.refTreeSearchAdd.getValue(this.formBasic.orgId); //机构赋值
      // });
    },

    // 表格
    // 数据预处理
    prepareData(data) {
      // 扁平化数据
      this.dataList = this.treeData.flatMap((item) => {
        if (item.patrolCategorys && Array.isArray(item.patrolCategorys)) {
          return item.patrolCategorys.map((child) => ({
            name: item.name,
            itemsId: item.id,
            content: child.content,
            categoryId: child.id,
          }));
        }
        return [];
      });
      // 生成合并规则
      this.calculateSpan();
    },

    // 生成合并规则数组
    // calculateSpan() {
    //   this.spanArr = [];
    //   this.treeData.forEach((item) => {
    //     const length = item.patrolCategorys.length;
    //     this.spanArr.push(length);
    //     for (let i = 1; i < length; i++) {
    //       this.spanArr.push(0);
    //     }
    //   });
    // },
    calculateSpan() {
      this.spanArr = [];
      let currentParentId = null;
      let currentParentCount = 0;

      this.dataList.forEach((item, index) => {
        if (currentParentId !== item.itemsId) {
          // 新的父节点
          currentParentId = item.itemsId;
          currentParentCount = 1;
          this.spanArr[index] = currentParentCount;
        } else {
          // 同一个父节点的子项
          this.spanArr[index] = 0;
          currentParentCount++;
          this.spanArr[index - 1] = currentParentCount;
        }
      });
    },

    // 合并单元格方法
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0) {
        const rowspan = this.spanArr[rowIndex];
        return { rowspan: rowspan, colspan: 1 };
      }
    },
    // ——————————————————————————————————————单位
    async getOrgList() {
      let { tenantId, userId, roleName } = this.user;
      const res = await reqOrgList({
        tenantId,
        userId,
        roleName,
        orgName: this.orgName || "",
        parentId: this.formBasic.orgId || "",
        type: "4",
      });
      if (res.code !== 20000) return this.$modal.notifyWarning(res.message);
      this.orgList = res.data.rows;
    },
    changeunitId() {
      this.formBasic.buildingId =
        this.formBasic.floorId =
        this.formBasic.spaceId =
          "";
      this.buildings = this.floors = this.spaces = [];
      this.sysInstanceIndex2 = 1;
      this.sysInstanceTotalPages2 = 10;
      this.sysInstanceIndex3 = 1;
      this.sysInstanceTotalPages3 = 10;
      this.getBuildList();
    },
    // 组织机构
    changeOrgId(instanceId) {
      if (this.isEditInfo) return;
      this.formBasic.orgId = instanceId.id;
      this.handleClear();
    },
    // 清空
    handleClear() {
      this.orgName = "";
      this.orgList = [];
      this.getOrgList();

      this.formBasic.unitId =
        this.formBasic.buildingId =
        this.formBasic.floorId =
        this.formBasic.spaceId =
          "";
      this.buildings = this.floors = this.spaces = [];
      this.formBasic.buildingId = this.formBasic.floorId = "";
      this.sysInstanceIndex = 1;
      this.sysInstanceTotalPages = 10;
      this.sysInstanceIndex2 = 1;
      this.sysInstanceTotalPages2 = 10;
      this.sysInstanceIndex3 = 1;
      this.sysInstanceTotalPages3 = 10;
    },

    // ——————————————————————————————————————建筑物
    // 选择建筑物
    changeBuildings(e) {
      this.formBasic.buildingId = e;
      this.clearFloors();
    },
    // 建筑物列表
    async getBuildList() {
      let res = await reqSpaceManager(this.sysInstanceIndex2, 10, {
        userId: this.user.userId,
        roleName: this.user.roleName,
        metaCode: 1,
        orgId: this.formBasic.unitId,
        isStatistics: 0,
        name: this.buildingsName,
      });
      if (res.code !== 20000) return this.$modal.notifyWarning(res.message);
      this.sysInstanceTotalPages2 = res.data.total;
      this.buildings = [...this.buildings, ...res.data.rows];
    },

    // 建筑物操作
    async loadBulidings() {
      if (this.sysInstanceIndex2 >= Math.ceil(this.sysInstanceTotalPages2 / 10))
        return;
      this.sysInstanceIndex2++;
      this.loading2 = true;
      // 获取列表数据的方法
      await this.getBuildList();
      this.loading2 = false;
    },

    // 远程搜索
    async remoteBuildings(query) {
      this.buildingsName = query; //保留输入的值
      this.buildingsName2 = query; //保留输入的值
      this.sysInstanceIndex2 = 1;
      this.sysInstanceTotalPages2 = 10;
      this.buildings = [];
      this.getBuildList();
    },
    // ——————————————————————————————————————楼层
    // 选择楼层
    changeFloors(e) {
      this.formBasic.floorId = e;
      this.clearSpaces();
    },
    // 清空楼层
    clearFloors() {
      this.formBasic.floorId = this.formBasic.spaceId = "";
      this.floorsName = "";
      this.floorsName2 = "";
      this.sysInstanceIndex3 = 1;
      this.sysInstanceTotalPages3 = 10;
      this.floors = this.spaces = [];
      this.getFloors();
    },
    // 远程搜索
    async remoteFloors(query) {
      this.floorsName = query; //保留输入的值
      this.floorsName2 = query; //保留输入的值
      this.sysInstanceIndex3 = 1;
      this.sysInstanceTotalPages3 = 10;
      this.floors = [];
      this.getFloors();
    },
    // 楼层操作
    async loadFloors() {
      if (this.sysInstanceIndex3 >= Math.ceil(this.sysInstanceTotalPages3 / 10))
        return;
      this.sysInstanceIndex3++;
      this.loading3 = true;
      // 获取列表数据的方法
      await this.getFloors();
      this.loading3 = false;
    },
    async getFloors() {
      let res = await reqSpaceManager(this.sysInstanceIndex3, 10, {
        userId: this.user.userId,
        roleName: this.user.roleName,
        metaCode: 2,
        orgId: this.formBasic.unitId,
        isStatistics: 0,
        name: this.floorsName,
        parentId: this.formBasic.buildingId || "",
      });
      if (res.code !== 20000) return this.$modal.notifyWarning(res.message);
      this.sysInstanceTotalPages3 = res.data.total;
      this.floors = [...this.floors, ...res.data.rows];
    },
    // ——————————————————————————————————————安装点
    // 选择安装点
    changeSpaces(e) {
      this.formBasic.spaceId = e;
    },
    // 清空安装点
    clearSpaces() {
      this.spacesName = "";
      this.spacesName2 = "";
      this.sysInstanceIndex4 = 1;
      this.sysInstanceTotalPages4 = 10;
      this.spaceId = "";
      this.spaces = [];
      this.getSpaces();
    },
    // 远程搜索
    async remoteSpaces(query) {
      this.spacesName = query; //保留输入的值
      this.spacesName2 = query; //保留输入的值
      this.sysInstanceIndex4 = 1;
      this.sysInstanceTotalPages4 = 10;
      this.spaces = [];
      this.getSpaces();
    },
    // 安装点操作
    async loadSpaces() {
      if (this.sysInstanceIndex4 >= Math.ceil(this.sysInstanceTotalPages4 / 10))
        return;
      this.sysInstanceIndex4++;
      this.loading4 = true;
      // 获取列表数据的方法
      await this.getSpaces();
      this.loading4 = false;
    },
    async getSpaces() {
      let res = await reqSpaceManager(this.sysInstanceIndex4, 10, {
        userId: this.user.userId,
        roleName: this.user.roleName,
        metaCode: 3,
        orgId: this.formBasic.unitId,
        isStatistics: 0,
        name: this.spacesName,
        parentId: this.formBasic.floorId || "",
      });
      if (res.code !== 20000) return this.$modal.notifyWarning(res.message);
      this.sysInstanceTotalPages4 = res.data.total;
      this.spaces = [...this.spaces, ...res.data.rows];
    },

    // ——————————————————————————————————————关联设备
    // 获取子组件传过来的设备数据
    getDevices(data) {
      this.treeData = data;
      this.prepareData();
    },

    // 点击复选框触发，可跨分页选择
    batchSelect(arr) {
      this.batchDataList = arr;
    },
    // 新增
    addClick() {
      // if (this.formBasic.orgId == "")
      //   return this.$modal.notifyWarning("请先选择组织机构");
      // if (this.formBasic.unitId == "")
      //   return this.$modal.notifyWarning("请先选择联网单位");
      // if (this.formBasic.buildingId == "")
      //   return this.$modal.notifyWarning("请先选择建筑物");
      // if (this.formBasic.floorId == "")
      //   return this.$modal.notifyWarning("请先选择楼层");
      // if (this.formBasic.spaceId == "")
      //   return this.$modal.notifyWarning("请先选择安装点");
      // if (this.dataList.length) {
      //   this.choseData = JSON.parse(JSON.stringify(this.dataList));
      // } else {
      //   this.choseData = [];
      // }
      this.$refs.refChoseDevice.dialogVisible = true;
    },
    // 批量删除
    onDelClickBatch() {
      this.batchDataList.forEach((item, index) => {
        if (item.type == 1) {
          this.choseData1 = this.choseData1.filter(
            (item1) => item1.imei != item.imei
          );
        }
        if (index == this.batchDataList.length - 1) {
          this.dataList = [...this.choseData1];
        }
      });
    },
    // 删除
    onDel(row) {
      this.treeData.forEach((item, index) => {
        if (item.id == row.itemsId) {
          item.patrolCategorys.forEach((item2, index2) => {
            if (item2.id == row.categoryId) {
              if (item.patrolCategorys.length == 1) {
                this.treeData.splice(index, 1);
              } else {
                item.patrolCategorys.splice(index2, 1);
              }
            }
          });
        }
      });
      this.prepareData();
    },

    // 维护人
    onFocus() {
      if (this.formBasic.orgId == "")
        return this.$modal.notifyWarning("请先选择组织机构");
      if (this.formBasic.unitId == "")
        return this.$modal.notifyWarning("请先选择联网单位");
      this.$refs.refChoseUser.dialogVisible = true;
    },
    getUsers(data) {
      // this.userData = data;
      // this.formMaintenance.serviceUser = data.map((item) => {
      //   return {
      //     userId: item.userId,
      //     username: item.username,
      //     nickname: item.nickname,
      //   };
      // });
      // this.formMaintenance.serviceUsers = data
      //   .map((item) => item.username)
      //   .join(",");
    },
    onBack() {
      this.closeDialog();
    },
    async onSubmit() {
      this.$refs.refFormBasic.validate(async (valid) => {
        if (valid) {
          // if (valid2) {
          let res;
          this.formBasic.tenantId = this.user.tenantId;
          // this.formBasic.deviceList = this.dataList.map((item) => {
          //   return {
          //     type: item.type,
          //     deviceCode: item.type == 1 ? item.imei : item.deviceCode,
          //     id: item.id,
          //     productType:
          //       item && item.productType ? item.productType : item.deviceType,
          //     spaceName: item.spaceName,
          //   };
          // });
          let addForm_copy = { ...this.formBasic, ...this.formMaintenance };
          addForm_copy.pointItemList = this.treeData.map((item) => {
            return {
              patrolItemId: item.id,
              categoryList: item.patrolCategorys.length
                ? item.patrolCategorys.map((item2) => {
                    return {
                      patrolItemId: item2.id,
                      categoryName: item2.categoryName,
                      content: item2.content,
                      remark: "",
                    };
                  })
                : [],
            };
          });
          if (JSON.stringify(this.editData) != "{}") {
            res = await reqPatrolPointUpdate(this.editData.id, addForm_copy);
            if (res.code !== 20000)
              return this.$modal.notifyWarning(res.message);
            this.$modal.notifySuccess("编辑成功");
          } else {
            res = await reqPatrolPointAdd(addForm_copy);
            if (res.code !== 20000)
              return this.$modal.notifyWarning(res.message);
            this.$modal.notifySuccess("新增成功");
          }
          this.$parent.getDataList();
          this.closeDialog();
        }
        // }
      });
    },
    closeDialog() {
      this.formBasic.deviceList = [];
      // this.formMaintenance.serviceUser = [];
      // this.formMaintenance.serviceUsers = "";
      this.userData = [];
      this.orgList = [];
      this.buildings = [];
      this.floors = [];
      this.spaces = [];
      this.choseData1 = [];
      this.dataList = [];
      this.orgName = "";
      this.$refs.refTable.clearSelection();
      this.$refs.refFormBasic.resetFields();
      this.$parent.isShowRuleOperate = false;
    },
  },
};
</script>

<style scoped lang="less">
@import url("./fpdOperate.less");
</style>
